# -*- coding: utf-8 -*-
#   三表单表简易编辑
# @Time    ： 2025/11/12  18:52
# @Auther  ： 徐良
# File     :  threeTableEdit.py


from typing import Optional, Union, Dict, Any
from PySide6.QtCore import Signal, Slot, QItemSelection, QModelIndex
from systemSet.ui.threePanelUI import Ui_Form
from PySide6.QtWidgets import QApplication
from baseClass.winPanel.baseQWidget import BaseQWidget
from baseClass.winPanel.interface_style import apply_styles
import ast


class ThreeTableEdit(BaseQWidget, Ui_Form):

    def __init__(self, p_dict:Dict[str, Any]=None,parent=None):
        super().__init__(parent)

        # self.DEFAULT_MS_DICT: Dict[str, Any] = ast.literal_eval(ms_dict)  # # 缺省的模块编码
        # # 创建工作类并初始化
        # self.create_factory(self.DEFAULT_MS_DICT)
        # # 创建单表工作类并初始化
        # self.create_table_work_class(self.DEFAULT_MS_DICT)


        apply_styles(self)


    def _init_map(self) -> None:
        """
        关系映射
        :return:
        """
        pass


    # region  工具栏命令，过滤返回， 行选择变化，表单双击
    def action_select(self, q):
        sel = q.text()
        if  sel == '导出':
            # obj_list = [('生产任务单', self.taskTableView),
            #             ('生产锅单', self.potTableView),
            #             ('领料单', self.pickTableView)]
            # to_excel = TableViewToXls(obj_list)
            # to_excel.to_excel_file()
            pass

    @Slot(QModelIndex)
    def on_tableview_double_clicked(self, index):
        """响应表格双击"""
        if index.isValid():
            row = index.row()
            sender = self.sender()  # 获取发送信号的对象
            model = sender.model()
            fid = model.record(row).value('FId')
        else:
            return

        ms_dict = self.DEFAULT_MS_DICT
        if sender.objectName() == 'taskTableView':
            ms_dict = {'msFNumber': '04.21', 'msClass': '10', 'msSaveType': 1, 'FPID': -1}

        elif sender.objectName() == 'potTableView':
            ms_dict = {'msFNumber': '04.01', 'msClass': '11', 'msSaveType': 1, 'FPID': -1}

        if sender.objectName() != 'pickTableView':

            self.create_factory(ms_dict)
            self.create_table_work_class(ms_dict)
            self.work_assistant_re_init()

        self.read_bill_data_for_edit(fid)

    @Slot(QItemSelection, QItemSelection)
    def on_selection_changed(self, selected, deselected) -> None:
        """

        :param selected:
        :param deselected:
        :return:
        """
        indexes = selected.indexes()
        if indexes:
            # sql = self.get_sql('potSql')
            # row = indexes[0].row()
            # task_number = self.taskModel.record(row).value('FBillNo')
            # condition = f" FTaskBillNo='{task_number}'"
            # sql = SqlFunction.add_where_str(sql, condition)
            # self._read_pot_data(sql)
            #
            # sql = self.get_sql('pickSql')
            # sql = SqlFunction.add_where_str(sql, condition)
            # self._read_pick_data(sql)
            pass

    # endregion


    # region 页面数据


    # endregion




if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)
    dic = "{'msFNumber':'05.01','msClass':'11', 'msSaveType':1, 'FPID':-1,'inspecType':0}"
    window = ThreeTableEdit()
    window.show()
    sys.exit(app.exec_())
